package com.witframework.core;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.hibernate.annotations.GenericGenerator;
import org.javalid.annotations.core.ValidateDefinition;

import com.witframework.WitException;
import com.witframework.core.annotations.Wit;
import com.witframework.core.structure.DynamicEnabled;
import com.witframework.util.BeanUtils;
import com.witframework.util.CloneableBean;

/**
 *  
 * Base Class for Model objects. 
 * All subtypes of a entity class should contain the naming is 'id' Attribute 
 * In fact should not be such, but now because of certain reasons, doesthis is must
 * 
 * @author wuxinyang
 *
 */
@MappedSuperclass @ValidateDefinition
public abstract class BaseEntity implements java.io.Serializable,DynamicEnabled{	
	
	
	@Wit(cnname="记录号",description="数据的记录号，用于表示数据的唯一编号")
	@Column(length=32)@Id @GeneratedValue(generator="wit-uuid") 
	@GenericGenerator(name="wit-uuid", strategy = "com.witframework.core.WitIdentifierGenerator")
	public String id ;	
	
	public Object get(String propName){		
		try {
			return BeanUtils.getDeclaredProperty(this,propName);
		} catch (Exception e) {
			throw new WitException(e);
		}
	}

	public void set(String propName, Object value) {		
		try {
			BeanUtils.setDeclaredProperty(this, propName, value);
		} catch (Exception e) {
			throw new WitException(e);
		}
	}	
	
	public Object cloneMe(){		
		CloneableBean _cloneableBean = new CloneableBean(this);		
		try {
			return _cloneableBean.beanClone();
		} catch (CloneNotSupportedException e) {
			throw new WitException(e);
		}
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}	
}
